package com.hjm.project.finance.agentDeductionsDetails.controller;

import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.finance.agentDeductionsDetails.domain.AgentDeductionsDetails;
import com.hjm.project.finance.agentDeductionsDetails.service.IAgentDeductionsDetailsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 扣款终端明细Controller
 * 
 * @author maker-platform
 * @date 2022-10-21
 */
@Controller
@RequestMapping("/finance/agentDeductionsDetails")
public class AgentDeductionsDetailsController extends BaseController {
    private String prefix = "finance/agentDeductionsDetails";

    @Resource
    private IAgentDeductionsDetailsService agentDeductionsDetailsService;

//    @RequiresPermissions("finance:agentDeductionsDetails:view")
    @GetMapping()
    public String agentDeductionsDetails(@RequestParam String serial, ModelMap map) {
        map.put("serial",serial);
        return prefix + "/agentDeductionsDetails";
    }

    /**
     * 查询扣款终端明细列表
     */
//    @RequiresPermissions("finance:agentDeductionsDetails:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentDeductionsDetails agentDeductionsDetails) {
        startPage();
        List<AgentDeductionsDetails> list = agentDeductionsDetailsService.selectAgentDeductionsDetailsList(agentDeductionsDetails);
        return getDataTable(list);
    }

    /**
     * 导出扣款终端明细列表
     */
//    @RequiresPermissions("finance:agentDeductionsDetails:export")
    @Log(title = "扣款终端明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentDeductionsDetails agentDeductionsDetails) {
        List<AgentDeductionsDetails> list = agentDeductionsDetailsService.selectAgentDeductionsDetailsList(agentDeductionsDetails);
        ExcelUtil<AgentDeductionsDetails> util = new ExcelUtil<AgentDeductionsDetails>(AgentDeductionsDetails.class);
        return util.exportExcel(list, "agentDeductionsDetails");
    }

    /**
     * 新增扣款终端明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存扣款终端明细
     */
    @RequiresPermissions("finance:agentDeductionsDetails:add")
    @Log(title = "扣款终端明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentDeductionsDetails agentDeductionsDetails) {
        return toAjax(agentDeductionsDetailsService.insertAgentDeductionsDetails(agentDeductionsDetails));
    }

    /**
     * 修改扣款终端明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        AgentDeductionsDetails agentDeductionsDetails = agentDeductionsDetailsService.selectAgentDeductionsDetailsById(id);
        mmap.put("agentDeductionsDetails", agentDeductionsDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存扣款终端明细
     */
    @RequiresPermissions("finance:agentDeductionsDetails:edit")
    @Log(title = "扣款终端明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentDeductionsDetails agentDeductionsDetails) {
        return toAjax(agentDeductionsDetailsService.updateAgentDeductionsDetails(agentDeductionsDetails));
    }

    /**
     * 删除扣款终端明细
     */
    @RequiresPermissions("finance:agentDeductionsDetails:remove")
    @Log(title = "扣款终端明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agentDeductionsDetailsService.deleteAgentDeductionsDetailsByIds(ids));
    }
}
